package com.pt25.base.validator.annotation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.Arrays;

public  class FixedValueValidator implements ConstraintValidator<FixedValues, String> {
    private String[] allowedValues;

    @Override
    public void initialize(FixedValues constraintAnnotation) {
        allowedValues = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return value != null && Arrays.asList(allowedValues).contains(value);
    }
}